package com.bulk.demo.insert.service.impl;

import com.bulk.demo.insert.entity.Student;
import com.bulk.demo.insert.mapper.StudentMapper;
import com.bulk.demo.insert.service.ITransactionInvalidationService;
import org.springframework.aop.framework.AopContext;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * service
 *
 * @author 散装java
 */
@Service
@Primary
public class TransactionInvalidationServiceImpl implements ITransactionInvalidationService {
    @Resource
    StudentMapper studentMapper;

    @Override
    @Transactional
    public void invalidationThis() {
        // mysql 5.7 默认 RR 隔离级别
        Student student = new Student();
        student.setName("散装java");
        studentMapper.insert(student);
        this.saveWithNotTransactional();
    }

    public void saveWithNotTransactional() {
        Student student = new Student();
        student.setName("谢pro");
        studentMapper.insert(student);
        throw new RuntimeException("手动异常");
    }

}
